package com.android.music.view;

import org.apache.http.impl.conn.SingleClientConnManager;

import com.android.music.R;

import android.R.integer;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.SumPathEffect;
import android.provider.ContactsContract.Contacts.Data;
import android.util.AttributeSet;
import android.view.View;

public class ClockSwingView extends View {

	private static final int NUM = 12;
	Paint paint = new Paint();
	Bitmap bitmap;
	private int startX;
	private int startY;
	private int stopX;
	private int stopY;
	private double radiux;
	private double sum = 0;
	private int[] spectrumData;

	public ClockSwingView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public ClockSwingView(Context context, AttributeSet attrs) {
		super(context, attrs);
		paint.setColor(getResources().getColor(R.color.blue));
		paint.setStyle(Style.FILL);

		bitmap = BitmapFactory.decodeResource(getResources(),
				R.drawable.decible_monitor_bg_1);
		stopX = bitmap.getWidth() / 2;
		stopY = bitmap.getHeight() / 2;
		radiux = (double) startY;

	}

	public void setStartX(int[] data, int isLeft) {
		// TODO Auto-generated method stub
		double angle = 0;
		for (int i = 0 + isLeft; i < NUM; i++) {
			sum += data[i];
			i++;
		}

		angle = sum / NUM * 90 / 60 + 45;
		startX = stopX - (int) (radiux * Math.cos(angle));
	}

	public void setStartY(int[] data, int isLeft) {
		double angle = 0;
		for (int i = 1 + isLeft; i < NUM; i++) {
			sum += data[i];
			i++;
		}

		angle = sum / NUM * 90 / 60 + 45;
		startY = stopY - (int) (radiux * Math.sin(angle));
	}

	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		canvas.drawLine(startX, startY, stopX, stopY, paint);
	}
}
